import pytest
from api.ihrmEmpManageApi import EmpManageApi
from common.assertTools import common_assert
from common.dbTools import DBTools
from common.getHeader import get_header
from common.readJsonTools import read_json_file
from config import TEL, BASE_PATH


class TestAddEmp(object):
    """添加员工接口的 测试类"""

    def setup_class(self):
        # 创建 emp 实例
        self.emp = EmpManageApi()
        self.req_header = get_header()

    def setup(self):
        """在每个普通方法执行前，自动调用"""
        DBTools.db_iud(f"delete from bs_user where mobile = '{TEL}';")

    def teardown(self):
        """测试结束后，自动调用，删除这个手机号"""
        DBTools.db_iud(f"delete from bs_user where mobile = '{TEL}';")

    file_name = BASE_PATH + "/data/addEmpData.json"

    data = read_json_file(file_name)

    @pytest.mark.parametrize("desc,req_body,status_code,success,code,message",data)
    def test_add_emp(self,desc,req_body,status_code,success,code,message):# 添加员工通用方法
        resp = self.emp.add_emp(self.req_header, req_body)
        print(desc,"：", resp.json())
        # 断言
        common_assert(resp, status_code, success, code, message)

